home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / flex_247.zip / flex_247 / MISC / fastwc / wc4.l < prev    next >
Text File  |  1993-07-22  |  658b  |  28 lines

  1. /* Fastest version of wc: add rules to pick up newlines, too */
  2.  
  3. ws    [ \t]
  4. nonws [^ \t\n]
  5. word  {ws}*{nonws}+
  6. words {word}{ws}+
  7.  
  8. %%
  9.     int cc = 0, wc = 0, lc = 0;
  10.  
  11. {word}{ws}*        ++wc; cc += yyleng;
  12. {word}{ws}*\n        ++wc; cc += yyleng; ++lc;
  13. {words}{word}{ws}*    wc += 2; cc += yyleng;
  14. {words}{word}{ws}*\n    wc += 2; cc += yyleng; ++lc;
  15. {words}{2}{word}{ws}*    wc += 3; cc += yyleng;
  16. {words}{2}{word}{ws}*\n    wc += 3; cc += yyleng; ++lc;
  17. {words}{3}{word}{ws}*    wc += 4; cc += yyleng;
  18. {words}{3}{word}{ws}*\n    wc += 4; cc += yyleng; ++lc;
  19.  
  20. {ws}+            cc += yyleng;
  21.  
  22. \n+            cc += yyleng; lc += yyleng;
  23.  
  24. <<EOF>>        {
  25.         printf( "%8d %8d %8d\n", lc, wc, cc );
  26.         yyterminate();
  27.         }
  28.